package com.rs.game.npc.glacor;

import com.rs.game.Animation;
import com.rs.game.Graphics;
import com.rs.game.Hit;
import com.rs.game.World;
import com.rs.game.WorldTile;
import com.rs.game.npc.NPC;
import com.rs.game.npc.combat.NPCCombatDefinitions;
import com.rs.game.npc.glacor.EnduringMinion;
import com.rs.game.npc.glacor.SappingMinion;
import com.rs.game.npc.glacor.UnstableMinion;

@SuppressWarnings("serial")
public class Glacor extends NPC {
		
	private int Stage;
	public boolean enduringMinionEffect;
	public boolean EnduringMinionSpawned;
	public boolean SappingMinionSpawned;
	public boolean UnstableMinionSpawned;
	public UnstableMinion unstable;
	public SappingMinion sapping;
	public EnduringMinion enduring;
	final NPCCombatDefinitions defs = getCombatDefinitions();
	final NPC thisNpc = this;

	public Glacor(int id, WorldTile tile, int mapAreaNameHash, 
			boolean canBeAttackFromOutOfArea) {
		super(id, tile, mapAreaNameHash, canBeAttackFromOutOfArea);
		this.setForceTargetDistance(5);
		setCapDamage(2500);
		setStage(0);
	}
	
	public void spawnMinions() {
		setNextAnimation(new Animation(9964));
		setNextGraphics(new Graphics(635));
		unstable = new UnstableMinion(14302, new WorldTile(this.getX() + 1,
				this.getY() + 1, this.getPlane()), -1, true, true, this);
		sapping = new SappingMinion(14303, new WorldTile(this.getX() + 1,
				this.getY(), this.getPlane()), -1, true, true, this);
		enduring = new EnduringMinion(14304, new WorldTile(this.getX() + 1,
				this.getY() - 1, this.getPlane()), -1, true, true, this);
		World.sendProjectile(this, unstable, 635, 34, 16, 30, 35, 16, 15);
		World.sendProjectile(this, sapping, 635, 34, 16, 30, 35, 16, 15);
		World.sendProjectile(this, enduring, 635, 34, 16, 30, 35, 16, 15);
		UnstableMinion.defeated = false;
		SappingMinion.defeated = false;
		EnduringMinion.defeated = false;
		setStage(1);
	}
	
	
	@Override
	public void handleIngoingHit(final Hit hit) {
		if (getStage() == 2 && enduringMinionEffect) {
		    hit.setDamage((int) (hit.getDamage() * 0.25));
		}
		if (UnstableMinion.defeated == false && SappingMinion.defeated == false && EnduringMinion.defeated == false && Stage == 1) {
		    hit.setDamage((int) (hit.getDamage() * 0));
		}
		if (UnstableMinion.defeated == true && SappingMinion.defeated == true && EnduringMinion.defeated == true) {
		    hit.setDamage((int) (hit.getDamage() * 1));
		}
	}

	@Override
	public void processEntity() {
		super.processEntity();	
		final NPCCombatDefinitions defs = getCombatDefinitions();
		
		if (getHitpoints() <= defs.getHitpoints() * 0.5 && getHitpoints() >= defs.getHitpoints() * 0.1 
				&& getStage() == 0) {
			spawnMinions();
			setCapDamage(0);
		}
		
		if (getHitpoints() <= 0 || isDead()) {
			enduringMinionEffect = false;
			setStage(0);
			UnstableMinion.defeated = false;
			SappingMinion.defeated = false;
			EnduringMinion.defeated = false;
		}
    }

	public int setStage(int Stage) {
		return (this.Stage = Stage);
	}

	public int getStage() {
		return Stage;
	}
}


